home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / gestalt.zip / GESTALT.C < prev    next >
Text File  |  1988-12-06  |  2KB  |  70 lines

  1. /* From 'Pattern Matching: The Gestalt Approach',
  2.    p46, Dr. Dobbs Journal, July 1988
  3.  
  4.    I just typed in the code.  I'm not a C programmer and don't have a
  5. decent C compiler handy, so this code is not tested (though I proofread
  6. for obvious typos, etc.).
  7.  
  8.    See SIMIL_C.ASM and SIMIL_C.OBJ for the C version of the similarity
  9. function.
  10.  
  11.    Read the comments in the function source (or the article itself
  12. in Dr. Dobbs) for detailed explanation.
  13.  
  14. David Kirschbaum
  15. Toad Hall
  16. kirsch@braggvax.ARPA
  17. */
  18.  
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. /*
  24. GESTALT.C
  25. Written by John W. Ratcliff and David E. Metzener
  26. November 10, 1987
  27.  
  28. Demonstrates the Ratcliff/Obershelp Pattern Recognition Algorithm
  29. Link this with SIMIL[_C].OBJ created from the SIMIL[_C].ASM source file.
  30. The actual similarity function is called as:
  31. int simil(char *str1,char *str2)
  32. where str1 and str2 are the two strings you wish to know their
  33. similarity value.  simil returns a percentage match between
  34. 0 and 100 percent.
  35. */
  36.  
  37. int    simil(char *str1,char *str2);
  38. void    ucase(char *str);
  39.  
  40. main()
  41. {
  42.   char    str1[80];
  43.   char    str2[80];
  44.   int    prcnt;
  45.  
  46. printf("This program demonstrates the Ratcliff/Obershelp pattern\n");
  47. printf("recognition algorithm.  Enter series of word pairs to\n");
  48. printf("discover their similarity values.\n");
  49. printf("Enter strings of 'END' and 'END' to exit.\n\n");
  50. do
  51.   {
  52.     printf("Enter the two strings separated by a space: ");
  53.     scanf("%s %s",str1,str2);
  54.     ucase(str1);
  55.     ucase(str2);
  56.     prcnt = simil(str1,str2);
  57.     printf("%s and %s are %d\% alike.\n\n",str1,str2,prcnt);
  58.   }    while (strcmp(str1,"END"));
  59. }
  60.  
  61. void ucase(str)
  62. char *str;
  63. {
  64. while (*str)
  65.   {
  66.     *str=toupper(*str);
  67.     str++;
  68.   }
  69. }
  70.